﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using yiCommerce.Areas.Admin.Models.Customers;
using yiCommerce.Attributes;
using yiCommerce.Controllers;
using yiCommerce.Core;
using yiCommerce.Core.Domain.Securitys;
using yiCommerce.Service.Customers;
using yiCommerce.Service.Securitys;

namespace yiCommerce.Areas.Admin.Controllers
{

    [AdminAuthorize(Order = 1)]
    [AdminCustomerAuthorize(Order = 2)]
    public class CustomerAdminController : BaseController
    {

        private IPermissionService _permissionService;

        private IWorkContext _workContext;

        private ICustomerService _customerService;

        public CustomerAdminController(ICustomerService customerService, 
            IPermissionService permissionService, IWorkContext workContext)
        {
            _customerService = customerService;
            _permissionService = permissionService;
            _workContext = workContext;
        }

        public ActionResult Index()
        {
            return RedirectToAction("List");
        }

        public ActionResult List()
        {
            var customers = _customerService.GetAllCustomers(0, 100);
            var model = new CustomerListModel()
                {
                    Customers = customers.Select(c=>new CustomerListItemModel()
                        {
                            
                            Email = c.Email,
                            Name = c.Username,
                            CustomerRoles = string.Join(",",c.CustomerRoles.Select(t=>t.SystemName).ToList())
                        }).ToList()
                };
            ViewBag.Model = model;
            return View();
        }


        public ActionResult Create()
        {
            var model = new CustomerEditModel()
                {
                    AvailableRoles = _customerService.GetAllCustomerRoles().Select(c => new CustomerRoleItemModel()
                        {
                            Id = c.Id,
                            Name = c.SystemName

                        }).ToList()
                };
            ViewBag.Model = model;
            return View("CreateOrEdit");
        }

        public ActionResult AssingCustomRole()
        {
            return View();
        }

        public ActionResult Edit()
        {
            return View();
        }
    }
}
